package com.xinchao.api;

import com.xinchao.constant.AdvertisementConstant;
import com.xinchao.exception.ServiceException;
import com.xinchao.service.AdvertisementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 广告Controller
 *
 * @author dxy
 * @date 2018/9/19 9:52
 */
@Controller
@RequestMapping(value = "/advertisement")
public class AdvertisementController {
	private static Logger logger = LoggerFactory.getLogger(AdvertisementController.class);
	@Autowired
	private AdvertisementService advertisementService;

	/**
	 * 获取广告列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list")
	public Object listAdvertisement(String advertiserName, String advertisementName, Integer advertisementStatus, Integer sex, String age,
	                                Integer pageNum, Integer pageSize) {
		try {
			return advertisementService.listAdvertisement(advertiserName, advertisementName, advertisementStatus, sex, age, pageNum, pageSize);
		} catch (ServiceException e) {
			logger.error("AdvertisementController listAdvertisement 获取广告列表列表失败：" + e.getMessage());
			return e;
		}
	}

	/**
	 * 获取广告状态列表
	 */
	@ResponseBody
	@RequestMapping(value = "/listStatus")
	public Object listStatus() {
		return AdvertisementConstant.ADVERTISEMENT_STATUS_MAP;
	}

	/**
	 * 获取年龄列表
	 */
	@ResponseBody
	@RequestMapping(value = "/listAge")
	public Object listAge() {
		return AdvertisementConstant.AGE_RANGE_LIST;
	}

	/**
	 * 获取性别列表
	 */
	@ResponseBody
	@RequestMapping(value = "/listSex")
	public Object listSex() {
		return AdvertisementConstant.SEX_MAP;
	}

}
